package com.sooth.micro.camunda.converter.bean;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import lombok.SneakyThrows;

import java.io.IOException;

@Data
public class ProcessModel {
    /**
     * 流程id
     */
    private String processId;

    /**
     * 流程名称
     */
    private String processName;

    private BaseDefinition processNode;

    public static ProcessModel of(String json) {
        ObjectMapper mapper =
                new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        ProcessModel result;
        try {
            result = mapper.readValue(json, ProcessModel.class);
        } catch (IOException e) {
            throw new RuntimeException(e.getMessage(), e.getCause());
        }
        return result;
    }

    @SneakyThrows
    @Override
    public String toString() {
        return new ObjectMapper().writeValueAsString(this);
    }
}
